package sv.ues.fia.basedatosap05029;

import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;

public class BaseDatosAP05029Activity extends ListActivity {
	String[] menu = { "Tabla Alumno", "Tabla Nota", "Tabla Materia","LLenar Base de Datos" };
	String[] activities = { "AlumnoMenuActivity", "NotaMenuActivity","MateriaMenuActivity" };
	ControlBDap05029 BDhelper;
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setListAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, menu));
		
		BDhelper=new ControlBDap05029(this);
	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		super.onListItemClick(l, v, position, id);
		if (position != 3) {
			String nombreValue = activities[position];
			try {
				Class<?> clase = Class.forName("sv.ues.fia.basedatosap05029."+ nombreValue);
				Intent inte = new Intent(this, clase);
				this.startActivity(inte);
			} catch (ClassNotFoundException e) {
				e.printStackTrace();
			}
		} else {
			BDhelper.abrir();
			String tost=BDhelper.llenarBDap05029();
			BDhelper.cerrar();
			Toast.makeText(this, tost, Toast.LENGTH_SHORT).show();			

			// CODIGO PARA LLENAR BASE DE DATOS
		}
	}
}